package com.openstack.javasdk;

import com.alibaba.fastjson.JSONObject;
import org.openstack4j.api.OSClient.OSClientV3;
import org.openstack4j.model.common.Identifier;
import org.openstack4j.model.identity.v3.Project;
import org.openstack4j.openstack.OSFactory;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping(value = "/projects")
public class ProjectModule {

//    You are not authorized to perform the requested action: identity:list_projects.
    @GetMapping("/all")
    public String allProject(){
        OSClientV3 os = Auth.getOS();
        List<? extends Project> projectList = os.identity().projects().list();
        return JSONObject.toJSONString(projectList);
    }

//    You are not authorized to perform the requested action: identity:get_project.
    @GetMapping("/query")
    public String queryProject(@RequestParam(value = "id")String id){
        OSClientV3 os = Auth.getOS();
        Project project = os.identity().projects().get(id);
        return JSONObject.toJSONString(project);
    }
}
